package pl.edu.utp.kursy.database.dao;

import java.util.ArrayList;
import java.util.List;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import pl.edu.utp.kursy.database.Academy;

public class AcademyDao extends BaseDao<Academy>{
    
    public AcademyDao(SessionFactory sessionFactory){
        super(sessionFactory);
    }
    
    @Override
    public Academy getById(int id) {
        Session session = sessionFactory.openSession();
        
        Criteria c = session.createCriteria(Academy.class);
        c.add(Restrictions.eq("id", id));    		    		
        Academy academy = (Academy)c.uniqueResult();
        
        session.close(); 
        return academy;
    }

    @Override
    public List<Academy> getAll() {
        ArrayList<Academy> academies;
        
        Session session = sessionFactory.openSession();
        Criteria c = session.createCriteria(Academy.class);
        academies = (ArrayList<Academy>)c.list();
        session.close();
        return academies; 
    }
    
}
